local Radius = 160
local IconSize = 8
local MPositionX = ScrW() - 200
local MPositionY = Radius - 55

local function DrawUDMiniMap()

	local LocalPos = LocalPlayer():GetPos()

	surface.SetDrawColor( 255, 255, 255, 255)
	surface.SetTexture( surface.GetTextureID( "radarbg" ) )
	surface.DrawTexturedRect(MPositionX - 5, MPositionY - 5, Radius + 10, Radius + 10)
	
	for _,v in pairs(ents.GetAll()) do
		if ValidEntity(v) then
			if v:IsPlayer() then
				clrMapIcon = Color(100, 255, 100, 255)
			end
			if v:IsNPC() then
				clrMapIcon = Color(200, 100, 100, 255)
			end
			if v:IsNPC() or v:IsPlayer() then 	
				if !clrMapIcon then return end
				local Distance = LocalPos - v:GetPos()
				
				Distance:Rotate( Angle(0, 180 - LocalPlayer():EyeAngles().y ,0) )
				local MapX = Distance.y * (Radius / ((InvasionSettings.RadarZoom * 1.5) + (Distance.z * 1.5)))
				local MapY = Distance.x * (Radius / ((InvasionSettings.RadarZoom * 1.5) + (Distance.z * 1.5)))

				local x1 = (MPositionX + (Radius / 2) - (IconSize / 2)) - MapX
				local y1 = (MPositionY + (Radius / 2) - (IconSize / 2)) - MapY
				local x2 = (MPositionX - 4) + ((Radius / 2))
				local y2 = (MPositionY - 4) + ((Radius / 2) )
				local radius1 = IconSize / 2
				local radius2 = Radius / 2
				
				--compare the distance to combined radii
				local dx = x2 - x1
				local dy = y2 - y1
				local radii = radius1 + radius2
				
				if  ( dx * dx )  + ( dy * dy ) < radii * radii then
					surface.SetDrawColor(clrMapIcon.r or 255, clrMapIcon.g or 255, clrMapIcon.b or 255, clrMapIcon.a or 255)
					surface.SetTexture(surface.GetTextureID("radarblip"))
					surface.DrawTexturedRect((MPositionX + (Radius / 2) - (IconSize / 2)) - MapX,(MPositionY + (Radius / 2 - (IconSize / 2))) - MapY, IconSize, IconSize)
				end
			end
		end
	end
end
hook.Add("HUDPaint", "DrawUDMiniMap", DrawUDMiniMap)